<?php

class Contract_model extends MY_Model {

    function __construct() {
        parent::__construct();
        $this->table = 'contract';
    }
    function find_all($sort="id",$oder="asc"){
    	$this->db->select('contract.*,product.product_name,provider.provider_name');
    	$this->db->join('product','product.id=contract.product_id');
    	$this->db->join('provider','provider.id=contract.provider_id');
    	$this->db->order_by('contract.' . $sort, $order);
    	$this->db->order_by('contract.update_date', 'desc');
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
    function getSearch($params, $sort = 'id', $order = 'asc') {
    	$this->db->select('contract.*,product.product_name,provider.provider_name');
    	if (isset($params['contract_name']) && $params['contract_name'] != '') {
    		$this->db->like('contract.contract_name', trim($params['contract_name']), 'both');
    	}
    	if (isset($params['member_id']) && $params['member_id'] != '') {
    		$this->db->where('contract.member_id', $params['member_id']);
    	}
    	if (isset($params['provider_id']) && $params['provider_id'] != '') {
    		$this->db->where('contract.provider_id', $params['provider_id']);
    	}
    	$this->db->join('product','product.id=contract.product_id');
    	$this->db->join('provider','provider.id=contract.provider_id');
    	$this->db->order_by('contract.' . $sort, $order);
    	$this->db->order_by('contract.update_date', 'desc');
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
}

?>